/**
 * 分红列表
 * Created by KY on 2017/4/18.
 */
define(['ldfw/core', 'art', 'comps/ajax',
        'text!tpl/dividend/list.tpl',
        'text!tpl/dividend/row.tpl',
        'bscroll',
        'ldfw/helper/formatHelper'],
    function (LDFW, artTemplate, ajax, tpl, rowTpl, BScroll) {
        return LDFW.Container.extend({
            tpl: tpl,
            events: {
                'click .list-group .list-item': 'gotoDetail'
            },
            initialize: function () {
                if(is_custom_skin && is_custom_skin.trim()){
                    this.model.set('is_custom_skin',is_custom_skin)
                    this.model.set('co_no',co_no)
                }
                this.once('shown', function () {
                    this.loadData()
                })
                this.loadData()
            },
            onCompAdd:function(comp){
                this.comp = comp
                this.comp.on('pullingDown',()=>{
                    this.loadData()
                })
            },
            loadData: function () {
                let _this = this
                $.when(ajax.post('pfL.1.207'),ajax.post('pfL.1.206'))
                    .done(function(resp1,resp2){
                        if(!_.isEmpty(resp2[0].result)){
                            _this.model.set(resp2[0].result[0])
                        }
                        if(!_.isEmpty(resp1[0].result)){
                            let html = artTemplate.compile(rowTpl)(resp1[0].result)
                            _this.$el.find('#dividendList').html(html)
                        }else{
                            _this.$el.find('.dividendContent').html(
                                `<div id="blank-page">
                                    <img class="blank-page" src="/assets/img/blank.png" alt="无" display>
                                    <p>你还没有分过红哦 </p>
                                </div>`
                            )
                        }
                        setTimeout(()=>{
                            _this.comp && _this.comp.forceUpdate()
                        },100)
                    })
            },
            gotoDetail: function (event) {
                let pd_no = $(event.currentTarget).attr('pd_no')
                LDFW.navigate('dividend/detail/'+pd_no)
            }
        })
    })